package org.example.message_queue.demo;

import org.example.message_queue.mqclient.Channel;
import org.example.message_queue.mqclient.Connection;
import org.example.message_queue.mqclient.ConnectionFactory;
import org.example.message_queue.mqserver.core.ExchangeType;

import java.io.IOException;

public class DemoProducer {
    public static void main(String[] args) throws IOException, InterruptedException {
        System.out.println("启动生产者");
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(9090);

        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare("testExchange", ExchangeType.DIRECT,true,false,null);
        channel.queueDeclare("testQueue",true,false,false,null);

//        创建消息并发送
        byte[] body = "helloworld".getBytes();
        boolean ok = channel.basicPublish("testExchange", null, null, body);
        System.out.println("消息投递完成！ok="+ok);

        Thread.sleep(500);
        channel.close();
        connection.close();
    }
}
